//
//  SNEncourageButton.m
//  project
//
//  Created by 黄建华 on 2018/8/27.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SNEncourageButton.h"

@implementation SNEncourageButton

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView
{
    
}

- (void)EncourageButtonClickWithImageName:(NSString *)name
{
    if (_imageV) {
        [_imageV removeFromSuperview];
        _imageV = nil;
    }

    _imageV = [[UIImageView alloc] init];
    _imageV.frame = SNFRAME(0, 0, 50, 50);
    _imageV.image = [UIImage imageNamed:name];
    [self addSubview:_imageV];

    CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    anima.toValue  = [NSNumber numberWithFloat:1.3];
    anima.duration = 0.8;
    [_imageV.layer addAnimation:anima forKey:@"scaleAnimation"];
    
    CABasicAnimation *anima2 = [CABasicAnimation animationWithKeyPath:@"opacity"];
    anima2.fromValue = [NSNumber numberWithFloat:1.0];
    anima2.toValue   = [NSNumber numberWithFloat:0.0];
    anima2.duration  = 0.8;
    [_imageV.layer addAnimation:anima2 forKey:@"opacityAniamtion"];
}

@end
